/*
 * @lc app=leetcode.cn id=1413 lang=javascript
 *
 * [1413] 逐步求和得到正数的最小值
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number}
 */
var minStartValue = function (nums) {
  let [min] = nums;
  let sum = 0;
  nums.forEach(num => {
    sum += num;
    min = Math.min(sum, min);
  })
  if (min >= 0) return 1;
  return 1 - min;
};
// @lc code=end
